/*
 * @Author: Drc
 * @Date: 2020-06-12 11:35:43
 * @LastEditors: Drc
 * @LastEditTime: 2021-11-03 14:27:35
 */

import React from 'react'
import {createStackNavigator, HeaderStyleInterpolators, CardStyleInterpolators} from '@react-navigation/stack'
import {} from 'react-native'
import {ThemeText} from '@path/components/ThemeComponents'
import BackImage from '@path/components/BackImage'
import Tab from './TabStack'
import Home, {HomeParams} from '@path/pages/home'
import User, {UserParams} from '@path/pages/user'
import WebView, {WebViewParams} from '@path/pages/common/WebView'

const Stack = createStackNavigator()

//路由配置
export const Screens = {
  Tab: {component: Tab, headerShown: false},
  Home: {component: Home},
  User: {component: User},
  WebView: {component: WebView},
}

//参数定义
export type Params = {
  Tab: {}
  Home: HomeParams
  User: UserParams
  WebView: WebViewParams
}

const MainStack = () => {
  return (
    <Stack.Navigator
      detachInactiveScreens={false} //FIXME:临时解决页面过渡闪烁白边
      screenOptions={() => {
        return {
          headerTitleAlign: 'center',
          headerTransparent: true,
          headerBackTitleVisible: false,
          headerStyleInterpolator: HeaderStyleInterpolators.forUIKit,
          cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
          headerBackTitle: '',
          headerTitle: (e) => {
            return <ThemeText style={{fontSize: 14, fontWeight: '400', ...e.style}}>{e?.children}</ThemeText>
          },
          headerBackImage: () => <BackImage />,
          headerMode: 'float',
        }
      }}>
      {Object.keys(Screens).map((screen) => {
        return (
          <Stack.Screen
            options={({}) => {
              return {
                headerShown: Screens[screen]?.headerShown ?? true,
                headerTintColor: '#000',
              }
            }}
            key={screen}
            name={screen}
            component={Screens[screen]?.component}
          />
        )
      })}
    </Stack.Navigator>
  )
}

export default MainStack
